﻿using StackExchange.Redis;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Shop.Core.Redis
{
    public interface IRedisProvider
    {
        /// <summary>
        /// https://redis.io/commands/get
        /// </summary>
        /// <param name="cacheKey"></param>
        /// <returns></returns>
        Task<string> StringGetAsync(string cacheKey);

        /// <summary>
        /// https://redis.io/commands/set
        /// </summary>
        /// <param name="cacheKey"></param>
        /// <param name="cacheValue"></param>
        /// <param name="expiration"></param>
        /// <param name="when">nx,xx,</param>
        /// <returns></returns>
        Task<bool> StringSetAsync(string cacheKey, string cacheValue, System.TimeSpan? expiration = null, string when = "");


        /// <summary>
        /// https://redis.io/commands/del
        /// </summary>
        /// <param name="cacheKey"></param>
        /// <returns></returns>
        Task<bool> KeyDelAsync(string cacheKey);

        /// <summary>
        /// 加锁
        /// </summary>
        /// <param name="cacheKey"></param>
        /// <param name="timeoutSeconds"></param>
        /// <returns></returns>
        Task<(bool Success, string LockValue)> LockAsync(string cacheKey, int timeoutSeconds = 5);

        /// <summary>
        /// 解锁
        /// </summary>
        /// <param name="cacheKey"></param>
        /// <param name="lockValue"></param>
        /// <returns></returns>
        Task<bool> SafedUnLockAsync(string cacheKey, string lockValue);
    }
}
